package com.young.hzh_learning

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.widget.AppCompatButton

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val soundPool = SoundPoolUtil.createSoundPool(1)

        val soundId = soundPool.load(assets.openFd("stun_gun.MP3"), 0)

        var streamID = soundId

        findViewById<AppCompatButton>(R.id.btn_play).setOnClickListener {
            streamID = soundPool.play(soundId, 1f, 1f, 1, 0, 1f)
        }

        findViewById<AppCompatButton>(R.id.btn_pause).setOnClickListener {
            soundPool.pause(streamID)
        }
    }
}